#define _CRT_SECURE_NO_WARNINGS 1

#include"sort.h"

void PrintArray(int* arr, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
}

void PrintPartArray(int* arr)
{
	for (int i = 0; i < 100; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
}
void TestOP()
{
	srand((unsigned int)time(NULL));
	const int N = 1000000;
	int* a1 = (int*)malloc(sizeof(int) * N);
	int* a2 = (int*)malloc(sizeof(int) * N);
	int* a3 = (int*)malloc(sizeof(int) * N);
	int* a4 = (int*)malloc(sizeof(int) * N);
	int* a5 = (int*)malloc(sizeof(int) * N);
	int* a6 = (int*)malloc(sizeof(int) * N);
	int* a7 = (int*)malloc(sizeof(int) * N);

	for (int i = 0; i < N; ++i)
	{
		a1[i] = rand() + i;
		a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];
		a6[i] = a1[i];
		a7[i] = a1[i];
	}

	int begin1 = clock();
	//InsertSort(a1, N);
	int end1 = clock();

	int begin2 = clock();
	ShellSort(a2, N);
	int end2 = clock();

	//PrintArray(a2, N);

	int begin3 = clock();
	//SelectSort(a3, N);
	int end3 = clock();

	int begin4 = clock();
	HeapSort(a4, N);
	int end4 = clock();

	int begin5 = clock();
	QuickSort2(a5, 0, N - 1);
	//QuickSort(a5, 0, N - 1);
	//QuickSortNonR(a5, 0, N - 1);
	int end5 = clock();

	int begin6 = clock();
	//MergeSort(a6, N);
	int end6 = clock();

	int begin7 = clock();
	CountSort(a7, N);
	int end7 = clock();

	printf("InsertSort:%d\n", end1 - begin1);
	printf("ShellSort:%d\n", end2 - begin2);
	printf("SelectSort:%d\n", end3 - begin3);
	printf("HeapSort:%d\n", end4 - begin4);
	printf("QuickSort:%d\n", end5 - begin5);
	printf("MergeSort:%d\n", end6 - begin6);
	printf("CountSort:%d\n", end7 - begin7);
	//PrintPartArray(a5);

	free(a1);
	free(a2);
	free(a3);
	free(a4);
	free(a5);
	free(a6);
	free(a7);
}
void TestInsertSort()
{
	int arr[] = { 1,4,5,6,7,3,2,8,9,10 };
	InsertSort(arr, sizeof(arr) / sizeof(int));
	PrintArray(arr, sizeof(arr) / sizeof(int));
}

void TestShellSort()
{
	int arr[] = { 1,4,5,6,7,3,2,8,9,10 };
	ShellSort(arr, sizeof(arr) / sizeof(int));
	PrintArray(arr, sizeof(arr) / sizeof(int));
}

void TestSelectSort()
{
	int arr[] = { 9,1,2,5,7,4,6,3 };
	SelectSort(arr, sizeof(arr) / sizeof(int));
	PrintArray(arr, sizeof(arr) / sizeof(int));
}

void TestHeapSort()
{
	int arr[] = { 9,1,2,5,7,4,6,3 };
	HeapSort(arr, sizeof(arr) / sizeof(int));
	PrintArray(arr, sizeof(arr) / sizeof(int));
}

void TestBubbleSort()
{
	int arr[] = { 9,1,2,5,7,4,6,3 };
	BubbleSort(arr, sizeof(arr) / sizeof(int));
	PrintArray(arr, sizeof(arr) / sizeof(int));
}

void TestQuickSort()
{
	int arr[] = {6,1,2,7,9,3,4,5,10,8,19,15,16,17,11,14,13,18,12,20,24,23,25,21,22};
	//QuickSort1(arr, 0,sizeof(arr) / sizeof(int) - 1);
	//QuickSort2(arr, 0, sizeof(arr) / sizeof(int) - 1);
	QuickSort(arr, 0, sizeof(arr) / sizeof(int) - 1);
	PrintArray(arr, sizeof(arr) / sizeof(int));
}

void TestQuickSortNonR()
{
	int arr[] = { 9,1,2,5,7,4,6,3 };
	QuickSortNonR(arr, 0, sizeof(arr) / sizeof(int) - 1);
	PrintArray(arr, sizeof(arr) / sizeof(int));
}

void TestMergeSort()
{
	int arr[] = { 6,1,2,7,9,3,4,5,10,8,19,15,16,17,11,14,13,18,12,20 };
	MergeSort(arr,sizeof(arr) / sizeof(int));
	PrintArray(arr, sizeof(arr) / sizeof(int));
}

void TestCountSortSort()
{
	int arr[] = { 6,1,2,7,9,3,4,5,10,8,19,15,16,17,11,14,13,18,12,20 };
	CountSort(arr, sizeof(arr) / sizeof(int));
	PrintArray(arr, sizeof(arr) / sizeof(int));
}


int main()
{
	//TestShellSort();
	//TestSelectSort();
	//TestHeapSort();
	//TestBubbleSort();
	TestQuickSort();
	//TestQuickSortNonR();
	//TestCountSortSort();
	
	
	//TestMergeSort();
	//TestOP();

	

	return 0;
}